//
//  SPBaseFansTeamTabTitleVC.m
//  ZXHT
//
//  Created by LSP on 2018/10/30.
//  Copyright © 2018 zxht. All rights reserved.
//

#import "SPBaseFansTeamTabTitleVC.h"

@interface SPBaseFansTeamTabTitleVC ()
@property (nonatomic, strong) IBOutlet UIView *titleView;
@property (nonatomic, strong) IBOutlet UIView *indicatorView;
@property (nonatomic, copy) IBInspectable NSString *tabTitles;
@end

@implementation SPBaseFansTeamTabTitleVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
}

- (void)setTabTitles:(NSString *)tabTitles {
    _tabTitles = tabTitles;
    if ([tabTitles isValidString]) {
        NSArray *titles = [tabTitles componentsSeparatedByString:@","];
        NSMutableArray *bts = [NSMutableArray arrayWithCapacity:titles.count];
        for (NSString *title in titles) {
            UIButton *bt = [UIButton buttonWithType:(UIButtonTypeCustom)];
            [bt setTitle:title forState:(UIControlStateNormal)];
            bt.titleLabel.font = self.unselectedFont;
            [bt setTitleColor:self.unselectedColor forState:(UIControlStateNormal)];
            [bt setTitleColor:self.selectedColor forState:(UIControlStateSelected)];
        }
        _titleBTs = [bts copy];
    }else{
        _titleBTs = @[];
    }
}

- (void)setCurrentIndex:(NSInteger)currentIndex {
    if (currentIndex < 0 ||
        currentIndex >= _titleBTs.count) {
        return;
    }
    _currentIndex = currentIndex;
    MJWeakSelf
    [_titleBTs enumerateObjectsUsingBlock:^(UIButton * _Nonnull bt, NSUInteger idx, BOOL * _Nonnull stop) {
        if (idx == currentIndex) {
            bt.selected = YES;
            bt.titleLabel.font = weakSelf.selectedFont;
        }else{
            bt.selected = NO;
            bt.titleLabel.font = weakSelf.unselectedFont;
        }
    }];
}

#pragma mark - Setters & Getters
- (UIColor *)selectedColor {
    if (!_selectedColor) {
        return [UIColor whiteColor];
    }
    return _selectedColor;
}
- (UIColor *)unselectedColor {
    if (!_unselectedColor) {
        return [UIColor colorWithHexStr:@"D4D4D4"];
    }
    return _unselectedColor;
}

- (UIFont *)selectedFont {
    if (!_selectedFont) {
        return [UIFont regularPingFangOfSize:18];
    }
    return _selectedFont;
}

- (UIFont *)unselectedFont {
    if (!_unselectedFont) {
        return [UIFont regularPingFangOfSize:15];
    }
    return _unselectedFont;
}

- (UIView *)titleView {
    if (!_titleView) {
        _titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 44)];
        _indicatorView = [[UIView alloc] initWithFrame:CGRectMake(0, 35, scaleBase375(50), 2)];
        _indicatorView.backgroundColor = [UIColor whiteColor];
        _indicatorView.layer.cornerRadius = 1;
        // TODO: 本控制器暂未完成，请勿使用
    }
    return _titleView;
}

@end
